package com.example.demoplus;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.demoplus.adapter.MenuAdapter;
import com.example.demoplus.bean.ShopBean;

public class ShopDetailActivity extends AppCompatActivity implements View.OnClickListener {
    private ShopBean shopBean;
    private TextView tvHeadShopName, tvTime, tvNotice, tvTitle;
    private ImageView ivShopPic, ivBack;
    private ListView lvList;
    private MenuAdapter menuAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_detail);
//        拿到从ShopAdapter中传来的数据
        shopBean = (ShopBean) getIntent().getSerializableExtra("shopBean");
//        判断传递过来的数据是否为空
        if (shopBean == null){
//            如果为空，结束页面
            return;
        }
//        添加寻找控件方法
        initView();
//        适配器方法
        initAdapter();
//        设置数据
        initData();

    }

    private void initAdapter() {
//        初始化
        menuAdapter = new MenuAdapter(this);
//        绑定菜单数据
        lvList.setAdapter(menuAdapter);
    }

    //  寻找控件方法
    private void initView() {
        tvHeadShopName = findViewById(R.id.tv_head_shop_name);
        tvTime = findViewById(R.id.tv_head_time);
        tvNotice = findViewById(R.id.tv_notice);
        tvTitle = findViewById(R.id.tv_title);
        ivShopPic = findViewById(R.id.iv_head_shop_pic);
        ivBack = findViewById(R.id.iv_back);
        lvList = findViewById(R.id.lv_list);
//        设置标题
        tvTitle.setText("店铺详情");
//        设置返回按钮可见
        ivBack.setVisibility(View.VISIBLE);
//        对返回按钮做监听 需要实现OnClickListener接口，并实现onClick方法
        ivBack.setOnClickListener(this);
    }
//    设置数据
    private void initData() {
        tvHeadShopName.setText(shopBean.getShopName());
        tvTime.setText(shopBean.getTime());
        tvNotice.setText(shopBean.getShopNotice());
        Glide.with(this).load(shopBean.getShopPic()).error(R.mipmap.ic_launcher).into(ivShopPic);
//        设置菜单食物数据
        menuAdapter.setData(shopBean.getFoodList());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
//            如果点击了
            case R.id.iv_back:
                finish();
                break;
        }
    }
}